/*
 * 
 * LegendShop 多用户商城系统
 * 
 *  版权所有,并保留所有权利。
 * 
 */
package com.legendshop.permission.service.impl;

import java.util.List;

import org.springframework.cache.annotation.Cacheable;

import com.legendshop.dao.support.PageSupport;
import com.legendshop.oa.model.Function;
import com.legendshop.oa.model.Permission;
import com.legendshop.permission.dao.FunctionDao;
import com.legendshop.permission.service.FunctionService;

/**
 * 权限服务.
 */
public class FunctionServiceImpl implements FunctionService {

	  private FunctionDao functionDao;
		/**
		 * 保存权限菜单
		 */
		@Override
		public boolean saveFuncMenu(Long funcId, Long menuId) {
			return functionDao.saveFuncMenu(funcId, menuId);
		}
		
		  /**
		   * 根据权限Id获取菜单列表
		   */
			@Override
			public List<Long> getMenuIdSByFuncId(Long funcId) {
				return functionDao.getMenuIdSByFuncId(funcId);
			}

		
		public void setFunctionDao(FunctionDao functionDao) {
			this.functionDao = functionDao;
		}
		

		/**
		 * 根据菜单ID拿到权限列表
		 */
		@Override
		@Cacheable(value = "GrantedFunctionList", key="'menu_'+#menuId")
		public List<Function> getFunctionsByMenuId(Long menuId) {
			return functionDao.getFunctionsByMenuId(menuId);
		}
	    

		/**
		 * 获取所有的权限
		 */
		@Override
		public List<Function> getAllFunction() {
			return functionDao.getAllFunction();
		}

		/**
		 * 根据URL地质获取权限
		 * @param url
		 * @return
		 */
		public List<Function> getFunctionsByUrl(String url){
			return functionDao.getFunctionsByUrl(url);
		}
		
		/**
		 * 根据用户ID查询用户拥有的系统权限信息
		 * @param userId
		 * @return 权限
		 */
		@Cacheable(value = "GrantedFunctionList", key="'sysuser_'+#userId")
		public List<Function> getSysFunctionByUserId(Long userId){
			return functionDao.getSysFunctionByUserId(userId);
		}
		
		/**
		 * 根据用户ID查询用户拥有的权限信息
		 * @param userId
		 * @return
		 */
		@Cacheable(value = "GrantedFunctionList", key="'user_'+#userId")
		public List<Function> getFunctionByUserId(Long userId) {
			return functionDao.getFunctionByUserId(userId);
		}


		@Override
		public PageSupport loadUserByFunction(String curPageNO, String userName, Long funcId) {
			return functionDao.loadUserByFunction(curPageNO,userName, funcId);
		}

		@Override
		public Function getFunctionsById(Long funcId) {
			return functionDao.getFunctionById(funcId);
		}

		@Override
		public List<Permission> getPermissionByRoleId(Long roleId) {
			return functionDao.getPermissionByRoleId(roleId);
		}

		@Override
		public PageSupport loadUserByRole(String curPageNO, String userName, Long roleId) {
			return functionDao.loadUserByRole(curPageNO, userName, roleId);
		}

		@Override
		public List<Function> getAllFunction(String appNo) {
			return functionDao.getAllFunction(appNo);
		}

		@Override
		public List<Function> getFunctionByUserId(Long userId, String appNo) {
			return functionDao.getFunctionByUserId(userId, appNo);
		}

		@Override
		public List<Function> getSysFunctionByUserId(Long userId, String appNo) {
			return functionDao.getSysFunctionByUserId(userId,appNo);
		}

		@Override
		public List<Function> getSysFunctionByAppNo(String appNo) {
			return functionDao.getSysFunctionByAppNo(appNo);
		}
		


}
